home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 005 / note11.arc / NOTE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1987-01-06  |  4.0 KB  |  157 lines

  1. {$include:'fink'}
  2.  
  3. program note(input,output);
  4.     uses filkqq(fcbfqq,filemodes,sequential,terminal,direct);
  5.  
  6. var
  7.     cmdlin : ads of lstring(128);
  8.     notebook : ads of string(80);
  9.     environ : ads of word;
  10.     cesxqq [extern] : word;
  11.     notefile : text;
  12.     book : lstring(255);
  13.     found,stamp,prompt,switch : boolean;
  14.     dstr,tstr : string(8);
  15.     inline : lstring(255);
  16.     txt_on_line : boolean;
  17.  
  18. procedure endxqq;extern;    { abort }
  19. procedure date(var dstr:string);extern;
  20. procedure time(var tstr:string);extern;
  21.  
  22. procedure find_string;        { locates the environment variable NOTEBOOK }
  23. var
  24.     i,j : integer;
  25.     tmp : string(9);
  26. begin
  27.     for j := 1 to 9 do
  28.         tmp[j] := notebook^[j];
  29.     if (tmp = 'NOTEBOOK=') then
  30.     begin
  31.         found := true;
  32.         i := 10;
  33.         j := 0;
  34.         while (notebook^[i] <> chr(0)) do
  35.         begin
  36.         j := j + 1;
  37.         book[j] := notebook^[i];
  38.         i := i + 1;
  39.         end;
  40.         book.len := wrd(j);
  41.     end else
  42.     begin
  43.         while (notebook^[1] <> chr(0)) do
  44.         notebook.r := notebook.r + 1;
  45.         notebook.r := notebook.r + 1;
  46.     end;
  47. end;
  48.  
  49. procedure give_ins;
  50. begin
  51.     writeln('Notebook program V1.1 - 1/6/87');
  52.     writeln('Tom Pfau - Digital Equipment Corporation, Parsippany, NJ');
  53.     writeln;
  54.     writeln('This program appends the text of the command line to a');
  55.     writeln('notebook file specified by the NOTEBOOK environment variable.');
  56.     writeln;
  57.     writeln('To use, do the following:');
  58.     writeln('    E>SET NOTEBOOK=E:\TEXT\NOTEBOOK.DAT');
  59.     writeln('Then, to add to the notebook, type:');
  60.     writeln('    E>NOTE This text will be appended to the file');
  61.     writeln;
  62.     writeln('You may optionally timestamp a message or have the program');
  63.     writeln('prompt for the text to be appended.');
  64.     writeln;
  65.     writeln('Command format:');
  66.     writeln('    NOTE [-s] [-p] [text]');
  67.     writeln('        -s    Record time of entry');
  68.     writeln('        -p    Prompt for text');
  69.     writeln;
  70.     writeln('In prompt mode, multiple lines of text can be entered for a');
  71.     writeln('single note.  The note will be delimited by start and end');
  72.     writeln('note markers.  If text appears after -p, that text will be');
  73.     writeln('written after the start note marker');
  74.     writeln;
  75. end;
  76.  
  77. begin {note}
  78.     found := false;
  79.     stamp := false;
  80.     prompt := false;
  81.     cmdlin.s := cesxqq;
  82.     cmdlin.r := 128;
  83.     while (cmdlin^[1] = ' ') do
  84.     begin
  85.         cmdlin^[1] := chr(cmdlin^.len - 1);
  86.         cmdlin.r := cmdlin.r + 1;
  87.     end;
  88.     txt_on_line := cmdlin^.len <> 0;
  89.     if not(txt_on_line) then
  90.     begin
  91.         give_ins;
  92.         endxqq;
  93.     end;
  94.     switch := false;
  95.     if (cmdlin^[1] = '-') then switch := true;
  96.     while switch do
  97.     begin
  98.         if (cmdlin^[2] = 's') then stamp := true
  99.         else if (cmdlin^[2] = 'p') then prompt := true
  100.         else switch := false;
  101.         if switch then
  102.         begin
  103.             cmdlin^[2] := chr(cmdlin^.len - 2);
  104.             cmdlin.r := cmdlin.r + 2;
  105.             while (cmdlin^[1] = ' ') do
  106.             begin
  107.             cmdlin^[1] := chr(cmdlin^.len - 1);
  108.             cmdlin.r := cmdlin.r + 1;
  109.             end;
  110.         if (cmdlin^[1] <> '-') then switch := false;
  111.         end;
  112.     end;
  113.     txt_on_line := (cmdlin^.len <> 0) or prompt;
  114.     environ.s := cesxqq;
  115.     environ.r := 44;
  116.     notebook.s := environ^;
  117.     notebook.r := 0;
  118.     while (not(found) and (notebook^[1] <> chr(0))) do find_string;
  119.     if not(found) or not(txt_on_line) then
  120.     begin
  121.         give_ins;
  122.         endxqq;
  123.     end;
  124.     assign(notefile,book);
  125.     notefile.trap := true;
  126.     reset(notefile);
  127.     if (notefile.errs <> 0) then
  128.     begin
  129.         notefile.errs := 0;
  130.         rewrite(notefile);
  131.     end else
  132.         while not(eof(notefile)) do readln(notefile);
  133.     notefile.inpt := false;
  134.     date(dstr);
  135.     time(tstr);
  136.     if prompt then
  137.     begin
  138.         write(notefile,'-- start note --');
  139.         if stamp then
  140.         write(notefile,' ',dstr,' ',tstr);
  141.         if (cmdlin^.len <> 0) then
  142.         write(notefile,' | ',cmdlin^);
  143.         writeln(notefile);
  144.         write('Note> ');
  145.         while not(eof(input)) do
  146.         begin
  147.         readln(inline);
  148.         writeln(notefile,inline);
  149.         write('Note> ');
  150.         end;
  151.         writeln(notefile,'-- end note --');
  152.     end else begin
  153.         if stamp then write(notefile,dstr,' ',tstr,' | ');
  154.         writeln(notefile,cmdlin^);
  155.     end;
  156. end.
  157.